package com.pixiv.Entity;

import com.pixiv.tools.ProgramStaticGlobal;
import org.apache.commons.io.IOUtils;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

@Scope("prototype")
@Component
public class TitleListPicture {
    private String picturePath;
    private String titleID;
    private int location;


    public String getPicturePath() {
        return picturePath;
    }

    public void setPicturePath(String picturePath) {
        this.picturePath = picturePath;
    }

    public String getTitleID() {
        return titleID;
    }

    public void setTitleID(String titleID) {
        this.titleID = titleID;
    }

    public int getLocation() {
        return location;
    }

    public void setLocation(int location) {
        this.location = location;
    }

    public void outputTitlePictureStream(HttpServletResponse resp)
    {

        String path = picturePath;
        File file = new File( ProgramStaticGlobal.getPRealPath() + "/title/auditcontext", path);

        try {
            FileInputStream fis = new FileInputStream(file);
            resp.setContentType("application/octet-stream; charset=utf-8");
            resp.setHeader("Content-Disposition", "attachment; filename=" + path);
            ServletOutputStream outputStream = resp.getOutputStream();
            IOUtils.copy(fis, outputStream);

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
